﻿#!/usr/bin/env perl
use strict;
use Encode;
use utf8;

if (! open FILE, "<", "20140404125738290.htm") {
	die "file is not exits."
}

if (! open OUTFILE, ">", "result.txt") {
	die "file is not exits."
}

my ($id, $count);

while (<FILE>) {
	chomp;
	#print "$count--{--$_--}--\n";
	
	#<td height=20 class=xl6810768 style='height:15.4pt'>110000000000</td>
	my $content;
	if ( $_ =~ /<td height=20 class=xl6810768 style='height:15.4pt'>([^<]*)<\/td>/){
		my ($id, $level, $name) = qw /null null null/;
		$id = "$1";
		
		if ($id eq "") {
			next;
		}
		
		#修正id信息
		$id = sprintf("%-18s",$id);
		$id =~ s/ /0/g;
		
		chomp($content .= readline(FILE));
		chomp($content .= readline(FILE));
		chomp($content .= readline(FILE));
		#print $content;
		#print "------------------------\n";
		
		if ( $content =~ /style='mso-spacerun:yes'>([^<]*)<\/span>([^<]*)<\/td>/) {
			my @tmp = split(/;/,$1);
			$level = $#tmp;
			$name  = $2;
		}
		print OUTFILE "$id:$level:$name\n";
	}
	
	$count += 1;
	
	if ($count > 500) {
		#last;
	}
}